package com.bpzj.web.spring;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author bpzj 2019/11/27 10:39 模拟并发时，多线程共同访问 unsafeName 变量，导致访问结果出错
 */
@RestController
public class ThreadUnsafe {

  private String unsafeName = "";

  @RequestMapping("/name")
  public String getName(@RequestParam String name) throws InterruptedException {
    unsafeName = name;
    Thread.sleep(1000L);
    return "name: " + unsafeName;
  }
}
